package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.fly.domain.Feedback;
import com.ruoyi.fly.domain.vo.DeleteVo;
import com.ruoyi.fly.domain.vo.FeedbackSearchVo;
import com.ruoyi.fly.domain.vo.FeedbackVo;
import com.ruoyi.fly.service.FeedbackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feedback")
@Api(tags = "反馈管理")
public class FeedbackController extends BaseController {

    @Autowired
    private FeedbackService feedbackService;


    /**
     * 查询反馈管理列表
     */
    @ApiOperation(value = "查询反馈管理列表")
    @PostMapping("/selList")
    public TableDataInfo list(@RequestBody FeedbackSearchVo feedbackSearchVo) {
        PageDomain pageDomain = new PageDomain();
        BeanUtils.copyProperties(feedbackSearchVo, pageDomain);
        startPage(pageDomain);
        List<FeedbackVo> list = feedbackService.selectFeedbackList(feedbackSearchVo);
        return getDataTable(list);
    }

    /**
     * 根据反馈id获取反馈详细信息
     */
    @ApiOperation(value = "根据反馈id获取反馈详细信息")
    @GetMapping(value = "/selId/{id}")
    public R<FeedbackVo> getInfo(@PathVariable("id") String id) {
        if (id == null){
            return R.fail("参数不能为空");
        }
        if (feedbackService.selectFeedbackById(id) == null){
            return R.fail("参数错误");
        }
        return R.ok(feedbackService.selectFeedbackById(id));
    }

    /**
     * 新增反馈
     */
    //@ApiOperation(value = "新增反馈")
    @PostMapping(value = "/add")
    public R add(@RequestBody Feedback feedback) {
        return feedbackService.insertFeedback(feedback);
    }

    /**
     * 修改反馈
     */
    //@ApiOperation(value = "修改反馈")
    @PostMapping(value = "/edit")
    public R edit(@RequestBody Feedback feedback) {
        return feedbackService.updateFeedback(feedback);
    }


    /**
     * 删除反馈
     */
    @ApiOperation(value = "删除反馈")
    @PostMapping("/delete")
    public R remove(@RequestBody DeleteVo deleteVo) {
        if (StringUtils.isEmpty(deleteVo.getIds())){
            return R.fail("参数不能为空");
        }
        return feedbackService.deleteFeedbackByIds(deleteVo.getIds());
    }
}
